
using System;
using System.Collections.Generic;
using BTKERP.Model;
using BTKERP.DAL.DataAccess;
using System;

namespace BTKERP.DAL
{
	#region UnitDAL
	public class UnitDAL : DBContext
	{
		public List<Unit> GetAll()
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_UnitsSelectAll");
            return GetEntityList<Unit>(cmd);
        }

        public Unit GetById(Guid id)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_UnitSelect");
            cmd.AddParameter("@Id", id);
            return GetSingleEntity<Unit>(cmd);
        }

		public List<Unit> GetByDynamicSQL(string sqlCondition)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_UnitSelectDynamic");
            cmd.AddParameter("@SQL", sqlCondition);
            return GetEntityList<Unit>(cmd);
        }

        public Unit Add(string paramName, string paramDescription, Guid paramUnitTypeId, string paramCreatedBy)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_UnitInsert");
            cmd.AddParameter("@Name", paramName);
            cmd.AddParameter("@Description", paramDescription);
            cmd.AddParameter("@UnitTypeId", paramUnitTypeId);
            cmd.AddParameter("@CreatedBy", paramCreatedBy);
            return GetSingleEntity<Unit>(cmd);
        }

        public bool DeleteById(Guid id)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_UnitDelete");
            cmd.AddParameter("@Id", id);
            return ExecuteCommand(cmd);
        }

        public Unit UpdateById(Guid paramId, string paramName,string paramDescription, Guid paramUnitTypeId, string paramUpdatedBy)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_UnitUpdate");
			cmd.AddParameter("@Id", paramId);
			cmd.AddParameter("@Name", paramName);
			cmd.AddParameter("@Description", paramDescription);
			cmd.AddParameter("@UnitTypeId", paramUnitTypeId);
			cmd.AddParameter("@UpdatedBy", paramUpdatedBy);
            return GetSingleEntity<Unit>(cmd);
        }
		
	}
	#endregion
}
